package com.tom.baselibrary.http;

import android.content.Context;
import android.util.Log;

import org.xutils.HttpManager;
import org.xutils.http.RequestParams;
import org.xutils.http.body.RequestBody;
import org.xutils.x;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;

import okhttp3.Request;

/**
 * Created by Tom on 2023/12/05.
 * 新增更加强大的网络第三方框架
 * 具体的访问实现，里面是具体的实现。
 */
public class XUtilsEngine implements IHttpEngine {
    private static final String TAG = "XUtilsRequest";
    private static HttpManager httpManager = x.http();

    private SPHttpCache mHttpCache;
    public XUtilsEngine() {
        mHttpCache = new SPHttpCache();
    }

    public void get(Context context, String url, Map<String, Object> params,
                    final EngineCallback httpCallBack, final boolean cache) {
        RequestParams requestParams = new RequestParams();
        httpManager.get(requestParams, new org.xutils.common.Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    @Override
    public void post(Context c, String url, Map<String, Object> params,
                     EngineCallback callback, boolean cache) {
        String joinUrl = HttpUtils.joinParams(url, params); // 用来调试打印。
        Log.e(TAG, "post: " + joinUrl);
        RequestParams requestParams = new RequestParams();

        httpManager.post(requestParams, new org.xutils.common.Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

}
